package com.sinosoft.controller;

import com.sinosoft.test.service.UserService;
import com.sinosoft.user.entity.dao.Order1Mapper;
import com.sinosoft.user.entity.model.Order1;
import com.sinosoft.vo.http.Result;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * Created by zoure on 2018/5/14.
 */
@Api(value = "用户信息1111", description = "检查模板操作111",tags="tag1")
@RestController("/user1")
@RefreshScope
public class User1Controller {
    private  Logger log = LoggerFactory.getLogger(getClass());
    @Value("${server.port}")
    private String serverPort;
    //@Value("${test.url}")  //通过配置中心得到远程配置
    private String datasourceUrl;
    @Autowired
    private UserService userService;
    @Autowired
    private Order1Mapper order1Mapper;
//    @Autowired
//    private CmsChannelMapper cmsChannelMapper;

    @ApiOperation("得到所有用户1111")
    @RequestMapping("/getAllUser1111")
    public List<String> getAllUser() {
        List<String> list = new ArrayList<String>();
        list.add("aaaaa");
        list.add("bbbb");
        list.add("port:" + serverPort);
        log.info("userService.getAllUser--log");

        return list;
    }
    @RequestMapping("/getSerivceName111")
    public String getSerivceName(){
        log.info("getSerivceName--log");
        return "this user serivce,port:" + serverPort+"   ,datasourceUrl:"+datasourceUrl;
    }

    @RequestMapping("/getConfigValue1111")
    public String getConifgValue(){
        log.info("getConifgValue--log");
        return "datasourceUrl:" + datasourceUrl;
    }
//    @RequestMapping("/testSQL")
//    public CmsChannel testSQL(){
//        log.info("testSQL");
//        CmsChannel cmsChannel = new  CmsChannel ();
////       CmsChannel cmsChannel =  cmsChannelMapper.selectByPrimaryKey("1667f0d1b9b341668fd1744d289b1a6a");
//        cmsChannelMapper.select1();
//        cmsChannelMapper.select2();
//        return cmsChannel ;
//    }
    @ApiOperation("保存用户11111")
    @ApiParam(name="id",value="用户id",required=true)
    @RequestMapping("/insert1111/{id}")
    public String insertMapper(@PathVariable  String id){
        Order1 order = new Order1();
        order.setId(id);
        order.setOrderName("");
        order.setCreateDate(new Date());
        order1Mapper.insertSelective(order);
        return "1111";
    }
    @ApiOperation("更新Order1")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单ID",paramType="query", dataType = "String"),
            @ApiImplicitParam(name = "key", value = "订单名",paramType="query", dataType = "String")
    })
    @RequestMapping("/update1111/{id}/{key}")
    @Transactional
    public String inupdateMapper(@PathVariable  String id,@PathVariable  String key){

        Order1 order = new  Order1();
        order.setId(id);
        order.setOrderName(key);
        order1Mapper.updateByPrimaryKeySelective(order);
      //  int a = 1/0;
        return "1111";
    }
    @ApiOperation("保存订单与用户1111")
    @ApiImplicitParam(name = "id", value = "订单ID",paramType="query", dataType = "String")
    @RequestMapping("/insertS11111/{id}")
    public String testService(@PathVariable  String id){
        userService.savea(id);

        return "1111";
    }
    @ApiOperation(value = "list<Order1>", notes = "List类型")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public Result<List<Order1>> list() {
            List<Order1> data = order1Mapper.selectAll();
            return  Result.ok().setData(data);
    }
    @ApiOperation(value = "Result<Map<String, Integer>>", notes = "Map类型")
    @RequestMapping(value = "mapOnly", method = RequestMethod.GET)
    public Result<Map<String, Integer>> mapOnly() {
        Map<String, Integer>data = new HashMap<>();
        data.put("a",1);
        data.put("b",2);
        return  Result.ok().setData(data);
    }
    @ApiOperation(value = "JsonResult«List«T»»", notes = "List类型")
    @RequestMapping(value = "list2", method = RequestMethod.GET)
    public Result<Order1> list2() {
        List<Order1> data = order1Mapper.selectAll();
        return  Result.ok().setData(data);
    }


}

